package eight.test_8_31;

import java.util.Scanner;

public class TestMain3 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] arr = new int[n];
        int count = 0;
        for (int i = 0; i < arr.length; i++) {
            arr[i] = scanner.nextInt();
        }

        while (true) {

                boolean b = true;
                for (int i = 1; i < n - 1; i++) {
                    if (arr[i - 1] > arr[i + 1]) {
                        int tmp = arr[i - 1];
                        arr[i - 1] = arr[i + 1];
                        arr[i + 1] = tmp;
                        b = false;
                    }
                }
                if (b) {
                    break;
                }

        }
        for (int i = 1; i < n - 1; i++) {
            if (arr[i] > arr[i - 1] && arr[i] > arr[i + 1]) {
                count++;
            }
            if (arr[i] < arr[i - 1] && arr[i] < arr[i + 1]) {
                count++;
            }
        }
        System.out.println(count);
    }

}
